fix(litellm): parse noncanonical tool call arguments#5756
Conversation
|
Note on the failing �gent-triage-pull-request check: this appears unrelated to this PR diff. The workflow runs python -m adk_pr_triaging_agent.main with PYTHONPATH=contributing/samples, while the package lives under contributing/samples/adk_team/adk_pr_triaging_agent, so the job fails before inspecting this change with ModuleNotFoundError: No module named 'adk_pr_triaging_agent'. |
|
Response from ADK Triaging Agent Hello @fancydirty, thank you for creating this PR! We appreciate your contribution to improve LiteLLM tool call parsing. This PR is looking great, but to help our reviewers process it more efficiently and in accordance with our contribution guidelines, could you please update the PR description to include the following:
This information will help reviewers to review your PR more efficiently. Thanks! |
|
Hi @fancydirty , Thank you for your contribution! We appreciate you taking the time to submit this pull request. Can you please fix the failing unit tests before we can proceed with the review. |
|
Hi @rohityan, thanks for the review. I pushed a follow-up commit to fix the pre-commit formatting failures, and updated the PR description with a dedicated testing plan plus local pytest/pre-commit output and the noncanonical-arguments verification logs requested by the triage bot. Current PR checks are green on my side. |
Summary
LiteLLM tool calls normally provide function.arguments as a strict JSON string, but some OpenAI-compatible providers can finalize a complete tool call with noncanonical object-literal syntax such as Python dict literals or unquoted JSON object keys. ADK currently passes the string directly to json.loads(...), which raises JSONDecodeError and aborts response conversion before the tool call can be surfaced.
This PR adds a small parser helper for LiteLLM tool call arguments:
The same parser is used for the streaming max-token/truncation check so complete noncanonical arguments are not mistaken for truncated arguments.
Why
Without this, a provider can stream a valid/intended tool call all the way to completion, but ADK crashes while converting the finalized LiteLLM message into LlmResponse.
testing plan
Passed locally on Python 3.10:
Pre-commit passed after applying formatting hooks:
Bug-fix verification for the noncanonical argument forms: